import type { FormDataType, PropsType, EmitUploadFile } from "../type"
// import { PropsType } from "../index.vue"
import http from "@/utils/http"
import { ElMessage } from "element-plus"
import { Ref } from "vue-demi"

function useUpdFile(
  props: PropsType,
  emit: EmitUploadFile,
  formData: FormDataType,
  modalFlag: Ref<boolean>
) {
  const updFile = async () => {
    if (!formData.name) {
      return
    }
    const res = await http.post("/file/updateFile", {
      name: formData.name,
      editable: formData.editable,
      fileId: formData.fileId,
    })

    if (res.code === 1) {
      ElMessage.success("修改成功")
      modalFlag.value = false
      emit("updateFile", props.parentId, props.handle)
    }
  }

  return { updFile }
}

export default useUpdFile
